package com.frain.springcloud.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.frain.springcloud.provide.ProvideInterface;
import com.frain.springcloud.provide.ProvideNoEurekaInterface;
import com.frain.springcloud.test.entity.User;

@Controller
@RequestMapping("/feign")
public class FeignClientController {

    @Autowired
    private ProvideInterface provideInterface;

    @Autowired
    private ProvideNoEurekaInterface provideNoEurekaInterface;

    @RequestMapping("/getDemo")
    @ResponseBody
    public String getDemoFind(HttpServletRequest request) {

        System.out.println("session=" + request.getSession().getId());
        System.out.println("thread=" + Thread.currentThread().getId());
        return provideInterface.getProviderDemo();
    }

    @RequestMapping("/getDemoHome")
    @ResponseBody
    public String getProviderHome() {
        return provideInterface.getProviderHome();
    }

    @RequestMapping("/get404")
    @ResponseBody
    public String getDemo404() {
        return provideInterface.get404Url();
    }

    @RequestMapping("/getUser")
    @ResponseBody
    public User getUser(Long id) {
        System.out.println("id===" + id);
        return provideInterface.getUserOne(id);
    }

    @RequestMapping("/getUserStringOne")
    @ResponseBody
    public String getUserStringOne(Long id) {
        System.out.println("id===" + id);
        return provideInterface.getUserStringOne(id);
    }

    @RequestMapping("/getUserStringOneByUser")
    @ResponseBody
    public String getUserStringOneByUser(User user) {
        System.out.println("user===" + user);
        return provideInterface.getUserStringOneByUser(user);
    }

    @RequestMapping("/getString")
    @ResponseBody
    public String getString() {

        return provideNoEurekaInterface.getString();
    }

}
